<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Greek Exercises</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="flashcard.css" rel="stylesheet" type="text/css">
</head>

<?php

try {
	$db = new PDO('sqlite:exercise.db3');
	$sentences = array();
	$q = $db->query("SELECT sentence, book, unit FROM exercises ORDER BY RANDOM() LIMIT 30;");
	$sentences = $q->fetchAll(PDO::FETCH_NUM);

	
	$db = NULL;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}

?>
<script type="text/javascript">
<?php
print "var sentences = new Array(".count($sentences).");\n";
for($i = 0; $i < count($sentences); $i++) {
	$tmp = $sentences[$i][0]." <span class=\"wl\">(".$sentences[$i][1].".".$sentences[$i][2].")</span>";
	print "sentences[$i] = ['$tmp'];\n";
}
?>

var shown = 0;

function updateVoc() {
	document.getElementById('v1').innerHTML = sentences[shown];
}

function next() {
	shown++;
	if (shown > sentences.length - 1) {
		shown = 0;
		alert('All done!');
	}
	updateVoc();
}

function prev() {
	shown--;
	if (shown < 0) {
		shown = sentences.length - 1;
		alert('All done!');
	}
	updateVoc();
}

</script>

<body onload="updateVoc()">

<h1 style="text-align:center">Kaegi’s Greek Exercises</h1>

<div class="center">

<div id="v1" class="v1"></div>


<a href="#" class="button" id="btnprev" onclick="prev()" accesskey="p">&lt;&lt;</a>
<a href="#" class="button" id="button" onclick="location.reload();">new</a>
<a href="#" class="button" id="btnnext" onclick="next()" accesskey="n">&gt;&gt;</a>



</div>
</body>
</html>
